package com.hotel.controllers;

import com.github.pagehelper.PageInfo;
import com.hotel.entitys.Fix;
import com.hotel.entitys.RestPOJO;
import com.hotel.services.FixService;
import com.hotel.services.RoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags="维护管理接口")//tags:说明信息
public class FixController {

    @Autowired
    private FixService fixService;
    @Autowired
    private RoomService roomService;

    @ApiOperation(
            value = "查询维护数据",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )


    @GetMapping("/fix")
    public RestPOJO getAllFix(Integer currentPage, Integer pageSize, String keyword){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Fix> pageInfo = fixService.getAllFix(currentPage,pageSize,keyword);
        if (pageInfo!=null && pageInfo.getList().size()>0){
            restPOJO.setMessage("查询维护数据成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(pageInfo);
        }else {
            restPOJO.setMessage("查询维护数据失败");
            restPOJO.setStatus(1001);
            restPOJO.setData(pageInfo);
        }
        return restPOJO;
    }
    @ApiOperation(
            value = "添加维护数据",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/fix")
    public RestPOJO addFix(@RequestBody Fix fix){
        RestPOJO restPOJO = new RestPOJO();
        int count = fixService.addFix(fix);
        return restPOJO;
    }
    @ApiOperation(
            value = "修改维护数据",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PutMapping("/fix/{fix_id}/{room_id}")
    public RestPOJO updateFix(@PathVariable("fix_id") Integer fix_id,@PathVariable("room_id") Integer room_id){
        System.out.println(fix_id);
        System.out.println(room_id);
        RestPOJO restPOJO = new RestPOJO();
        int countFix = fixService.updateFix(fix_id);
        int count = roomService.cleanRoom(room_id);
        if (countFix > 0 && count > 0){
            restPOJO.setMessage("维护完成");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("维护失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }
}
